<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_auth_info extends AdminController{
    public $_validation = null;

    function __construct(){
        parent::__construct();
        $this->load->model('MUserAuthInfo');
        $this->_validation = Array(
            array('field'=>'user_id', 'label'=>'用户ID', 'rules'=>'required|max_length[11]')
            ,array('field'=>'real_name', 'label'=>'真实姓名', 'rules'=>'max_length[64]')
            ,array('field'=>'id_num', 'label'=>'身份证号', 'rules'=>'max_length[32]')
            ,array('field'=>'face_idcard', 'label'=>'身份证正面', 'rules'=>'max_length[255]')
            ,array('field'=>'back_idcard', 'label'=>'身份证背面', 'rules'=>'max_length[255]')
            ,array('field'=>'remark', 'label'=>'备注', 'rules'=>'max_length[255]')
            ,array('field'=>'status', 'label'=>'认证状态', 'rules'=>'integer|max_length[2]')
            ,array('field'=>'create_time', 'label'=>'创建时间', 'rules'=>'integer')
            ,array('field'=>'update_time', 'label' => '更新时间', 'rules' => 'integer')
        );
    }

    function index(){
        //$this->output->enable_profiler(TRUE);
        $this->load->library('FormFilter');
        $this->load->helper('formfilter');
        $this->formfilter->addFilter('real_name', 'where');
        $this->formfilter->addFilter('id_num', 'where');
        $this->formfilter->addFilter('nick_name', 'like');
        $this->formfilter->addFilter('status', 'where');

        if ($begintime = filterValue('user_auth_info_create_time_begin')) {
            $this->formfilter->addFilter('user_auth_info_create_time_begin', 'where', array('create_time >= ', strtotime($begintime . ' 00:00:00')));
        }
        if ($endtime = filterValue('user_auth_info_create_time_end')) {
            $this->formfilter->addFilter('user_auth_info_create_time_end', 'where', array('create_time <= ', strtotime($endtime . ' 23:59:59')));
        }
        $number_perpage = filterValue('user_auth_info_number_perpage');
        $total_number = $this->MUserAuthInfo->getCount();
        $limit = $this->pagination($total_number,'',$number_perpage);
        $list  = $this->MUserAuthInfo->getList($limit);
        $this->assign('list', $list);
        $this->layout();
    }

    public function auth_confirm(){
        $data = $this->input->post();
        $info = $this->MUserAuthInfo->getById($data['id']);
        if ($this->db->update('user_auth_info',['status' => $data['status'], 'remark' => $data['remark']],['id' => $data['id']]) && $this->db->update('user',['auth_status' => $data['status']],['id' => $info->user_id])){
            exit(json_encode([
                'status' => 1,
                'msg' => '操作成功'
            ]));
        }else{
            exit(json_encode([
                'status' => 0,
                'msg' => '操作失败'
            ]));
        }
    }
}
